package com.evil.application.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.evil.application.pojo.entity.ApplicationQueue;
import com.evil.common.account.dto.user.UserEnterpriseDTO;
import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.enums.SwitchEnum;
import com.evil.common.core.exception.BusinessException;

import java.util.List;
import java.util.Optional;

/**
 * 应用队列表
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
public interface ApplicationQueueMapper extends BaseMapper<ApplicationQueue> {

    default Optional<ApplicationQueue> findById(Long id) {
        return Optional.ofNullable(this.selectById(id));
    }

    default ApplicationQueue isExistById(Long id) {
        return this.findById(id).map(e -> {
            if (SwitchEnum.isOpen(e.getIsDeleted())) {
                throw new BusinessException(RCodeEnum.APPLICATION_QUEUE_DELETED);
            }
            return e;
        }).orElseThrow(() -> new BusinessException(RCodeEnum.APPLICATION_QUEUE_NOT_EXIST));
    }

    /**
     * 企业用户 应用队列
     *
     * @param userEnterpriseDTO userEnterpriseDTO
     * @return List
     */
    List<ApplicationQueue> findByUserEnterprise(UserEnterpriseDTO userEnterpriseDTO);
}